use godot::prelude::*;

pub trait TryAsSingle {
    fn try_as_single(self) -> Result<f32, ()>;
}

impl TryAsSingle for Variant {
    fn try_as_single(self) -> Result<f32, ()> {
        match self.get_type() {
            VariantType::FLOAT => Ok(self.to()),
            VariantType::INT => Ok(self.to::<i64>() as f32),
            _ => Err(())
        }
    }
}